package org.mango.controller;

import com.alibaba.fastjson.JSON;
import org.jangod.iweb.core.action.AbstractController;
import org.mango.bean.DemoBean;
import org.mango.exception.FluentValidateException;
import org.mango.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by meigang on 17/9/11.
 */
@Controller
@RequestMapping("/demo")
public class DemoController extends AbstractController {


    @Autowired
    private DemoService demoService;

    @RequestMapping("/index")
    public String index(){

        return "index";
    }
    @RequestMapping("/add")
    public String addDemo(DemoBean demoBean){
        try{
            demoService.addDemo(demoBean);
            this.setAttr("data", JSON.toJSONString(demoBean));
        }catch (FluentValidateException fve){
            System.out.println(fve.toString());
            this.setAttr("data",fve.getMessage());
        }

        return "index";
    }

}
